require(["config"],function(){
    require(["jquery","swiper","template","header"],($,Swiper,template)=>{
        
        function Index(){
            this.init();
        }
        Index.prototype={
            constructor:Index,
            init(){

                this.swiper();
                this.render();
                // this.jump();
            },

                swiper(){

                    var mySwiper = new Swiper('#swiper1', {
                        // 垂直切换选项
                     //    direction: 'vertical',
                     autoplay: true,
                         loop: true, // 循环模式选项
                         
                         // 如果需要分页器
                         pagination: {
                           el: '.swiper-pagination',
                           clickable :true,
                         },
                         
                         // 如果需要前进后退按钮
                         navigation: {
                           nextEl: '.swiper-button-next',
                           prevEl: '.swiper-button-prev',
                         },
                         
                         // 如果需要滚动条
                         scrollbar: {
                           el: '.swiper-scrollbar',
                         },
                       }) 
                    
                },
                render(){
                    $.getJSON("http://rap2api.taobao.org/app/mock/116724/list",$.proxy(this.handlerData,this));
                    },
                handlerData(data){
                   
                        var data={list:data.res_body.list}
                    
                        var html = template("list-template",data);
                        $("#swiper-wrapper2").html(html);
                        var mySwiper = new Swiper('#swiper2', {
                            // autoplay: true,//可选选项，自动滑动
                            slidesPerView:4,
                            spaceBetween :5,
                            navigation: {
                                nextEl: '.swiper-button-next',
                                prevEl: '.swiper-button-prev',
                              },
                           });
                           this.link();
                },
                link(){
                    $(".products").delegate(".prod-id","click",function(){
                     
                        var prodSrc = $(this).data("src");
                      
                        window.location.href=`/html${prodSrc}`;
                    })
                    
                },
                // jump:function(){
                //     $("body").on("click","data-src")
                // }

                    
                   
                             
            
        }
       new Index();
    })
})